package forwardredirect;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/forward")
public class ForwardServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 给请求添加属性
		req.setAttribute("name", "zhangsan");
		// 请求得到转发器(参数：要转发的路径)
		RequestDispatcher dispatcher = req.getRequestDispatcher("/a");
		// RequestDispatcher dispatcher = req.getRequestDispatcher("http://www.baidu.com");
		// 转发
		dispatcher.forward(req, resp);
	}
}
